package com.jiazhong.boot.mvc.controller;

import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.IOException;
import java.io.PrintWriter;

@Slf4j
@Controller
@RequestMapping("/third")
public class ThirdController {

    @RequestMapping("/a")
    public String a() {
        log.info("用户访问了ThirdController的a方法！");
        return "redirect:/a.html";
    }

    @RequestMapping("/b")
    public String b(HttpServletRequest request, HttpServletResponse response) throws IOException {
        HttpSession session = request.getSession();
        ServletContext application = session.getServletContext();
        PrintWriter out = response.getWriter();
        log.info("request:{}", request);
        log.info("response:{}", response);
        log.info("session:{}", session);
        log.info("application:{}", application);
        log.info("out:{}", out);
        log.info("用户访问了ThirdController的b方法！");
        return "redirect:/a.html";
    }
}
